fix(pivot-grid): Handle currency pivot values with count aggregator - 19.2.x#15428
fix(pivot-grid): Handle currency pivot values with count aggregator - 19.2.x#15428
Conversation
projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid-state.service.ts
Outdated
Show resolved
Hide resolved
| valueChipTemplate: TemplateRef<any>; | ||
| rowDimensionHeaderTemplate: TemplateRef<IgxColumnTemplateContext>; | ||
| /** @hidden @internal */ | ||
| currencyColumnSet: Set<string> |
There was a problem hiding this comment.
Do we need to store the current currency columns? It doesn't seem to matter what their individual dataType is as we need to change them all anyway based on the IPivotValue's dataType and current selected aggregator.
-
pivot value with
dataType= "currency" + selected aggregator with aggregatorName: "COUNT" => All columns associated with it need to setdataType= "number" (doesn't matter what their state was before that). -
pivot value with
dataType= "currency" + selected aggregator with aggregatorName: "Not COUNT"=> All columns associated with it need to setdataType= "currency" (doesn't matter what their state was before that).
Also there's a third numeric data type: GridColumnDataType.Percent which we should also consider. It should also change the column types to number for Count.
| private handleCountAggregator() { | ||
| const valueMember = this.value.member; | ||
| const columns = this.grid.columns; | ||
| const isCountAggregator = this.value.aggregate.key.toLowerCase() === 'count'; |
There was a problem hiding this comment.
The key is user set and will not necessarily match with count. Would be better to check aggregatorName or the actual aggregator.
|
|
||
| columns.forEach(column => { | ||
| const isRelevantColumn = column.field?.includes(valueMember); | ||
| const isCurrencyColumn = column.dataType === GridColumnDataType.Currency; |
There was a problem hiding this comment.
We don't care about the individual columns dataType. Just if the value's dataType is currency or percent.
- If it is and has count aggregator -> all column become number.
- If it does not have a count aggregator -> all columns become currency.
No need to store and manage column state.
| } | ||
| } | ||
|
|
||
| private handleCountAggregator() { |
There was a problem hiding this comment.
There's a method with the same name and same code in the pivot selector. Perhaps set it somewhere where it can be re-used. Maybe in the pivot grid component since both should have access to it or in as a common util function?
|
|
||
| if ((value.dataType === GridColumnDataType.Currency || value.dataType === GridColumnDataType.Percent) && isCountAggregator) { | ||
| columns.forEach(column => { | ||
| console.log(column.field?.includes(value.member)) |
| public static handleCountAggregator(columns: ColumnType[], value: IPivotValue, isSingleValue: boolean): void { | ||
| const isCountAggregator = value.aggregate.aggregator?.name?.toLowerCase() === 'count' || value.aggregate.aggregatorName?.toLowerCase() === 'count'; | ||
|
|
||
| if ((value.dataType === GridColumnDataType.Currency || value.dataType === GridColumnDataType.Percent) && isCountAggregator) { |
There was a problem hiding this comment.
These checks are a bit repetitive as is the code in the ```if``'s. The same ones are in updateColumnDataTypeByAggregator and in `generateColumnHierarchy`. Maybe just extract it in a common util method that gets the column type for a given PivotValue and reuse it. It would also make the code a bit more readable:
public static updateColumnTypeByAggregator(columns: ColumnType[], value: IPivotValue, isSingleValue: boolean): void {
const targetColumnType = getColumnDataTypeForValue(value);
columns.forEach(column => {
if (column.field?.includes(value.member) || isSingleValue) {
column.dataType = targetColumnType;
}
});
}
Closes #15148
Additional information (check all that apply):
Checklist:
feature/README.MDupdates for the feature docsREADME.MDCHANGELOG.MDupdates for newly added functionalityng updatemigrations for the breaking changes (migrations guidelines)